<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="_csrf" th:content="${_csrf.token}"/>
    <meta name="_csrf_header" th:content="${_csrf.headerName}"/>
    <title>新Share</title>
    <script th:src="@{/static/ckeditor/ckeditor.js}"></script>
</head>
<body>

<div th:replace="header :: nav"></div>

<script>
    function newShare() {
        var token = $("meta[name='_csrf']").attr("content");
        var header = $("meta[name='_csrf_header']").attr("content");
        var title = $("#title").val();
        var content = CKEDITOR.instances.editor1.getData();
        if(title==""||content==""){
            alert("不能为空")
            return;
        }
        var description = CKEDITOR.instances.editor1.document.getBody().getText();
        var share = {
            "title":title,
            "content":content,
            "description":description
        }
        $.ajax({
            url: "/newShare",
            type:"POST",
            beforeSend: function(request) {
                request.setRequestHeader(header, token);
            },
            timeout:5000,
            data: share,
            success: function (result) {
                window.location.href="/index.html?size=5&sort=publishTime,desc";
            },
            error:function (err) {
                alert("网络错误！"+err.toString());
            }
        });
    }

</script>
<div class="container">

    <div th:replace="header :: meLeft"></div>

    <div class="col-xs-10">
        <div class="form-horizontal">
            <div class="form-group">
                <label for="title" class="col-xs-1 control-label">标题:</label>
                <div class="col-xs-9">
                    <input type="text" class="form-control" id="title" placeholder="Title">
                </div>
            </div>
            <div class="form-group">
                <textarea name="editor1" id="editor1">
                    完整代码请放到github上
                </textarea>
                <script>
                    // Replace the <textarea id="editor1"> with a CKEditor
                    // instance, using default configuration.
                    CKEDITOR.replace('editor1',{
                        customConfig: '/static/ckeditor/config.js'
                    });
                </script>
            </div>
            <div class="form-group">
                <button class="btn btn-default" onclick="newShare()">发布</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>